<template>
  <div class="order-list-container">
    <button class="back-button" @click="goBack">
      <span class="back-icon">←</span>
      <span class="back-text">返回</span>
    </button>

    <div class="page-header">
      <h1 class="page-title">我的订单</h1>
      <div class="order-tabs">
        <button v-for="tab in tabs" :key="tab.value" :class="['tab-btn', { active: currentTab === tab.value }]"
          @click="setTab(tab.value)">
          {{ tab.label }}
        </button>
      </div>
    </div>

    <div v-if="loading" class="loading-container">
      <div class="loading-spinner"></div>
      <p>加载中...</p>
    </div>

    <div v-else-if="error" class="error-container">
      <p>{{ error }}</p>
      <button @click="fetchOrders" class="retry-btn">重试</button>
    </div>

    <div v-else-if="filteredOrders.length === 0" class="empty-state">
      <i class="fas fa-box-open"></i>
      <p>暂无相关订单</p>
    </div>

    <div v-else class="order-list">
      <div v-for="order in paginatedOrders" :key="order.id" class="order-card">
        <div class="order-header">
          <div class="order-info">
            <span class="order-id">订单号：{{ order.orderNo }}</span>
            <span class="order-date">下单时间：{{ order.createTime }}
              
            </span>
          </div>
          <span class="order-status" :class="'status-' + order.status">{{ getStatusText(order.status) }}</span>
        </div>

        <div class="order-items">
          <div v-for="(item, index) in order.orderItems" :key="index" class="order-item">
            <div class="item-image">
              <img :src="item.productImage || 'https://via.placeholder.com/100'" :alt="item.productName">
            </div>
            <div class="item-info">
              <h3 class="item-name">{{ item.productName }}</h3>
              <div class="item-price-qty">
                <span class="price">¥{{ formatPrice(item.price) }}</span>
                <span class="quantity">x{{ item.quantity }}</span>
              </div>
            </div>
          </div>
        </div>

        <div class="order-footer">
          <div class="order-total">
            <span>共{{ getTotalQuantity(order.orderItems) }}件商品</span>
            <span class="total-price">实付款：¥{{ formatPrice(order.actualAmount) }}</span>
          </div>
          <div class="order-actions">
            <!-- 未支付状态 -->
            <template v-if="order.status === 0">
              <button class="action-btn primary" @click="handlePay(order)">
                去支付
              </button>
              <button class="action-btn" @click="handleCancel(order)">
                取消订单
              </button>
            </template>

            <!-- 已支付状态 -->
            <template v-else-if="order.status === 1">
              <span class="status-badge paid">已支付</span>
              <button class="action-btn" @click="handleCancel(order)">
                取消订单
              </button>
            </template>

            <!-- 已取消状态 -->
            <template v-else-if="order.status === 2">
              <span class="status-badge cancelled">已取消</span>
            </template>

            <!-- 已发货状态 -->
            <template v-else-if="order.status === 3">
              <span class="status-badge shipped">已发货</span>
              <button class="action-btn warning" @click="handleReturn(order)">
                申请退货
              </button>
              <button class="action-btn primary" @click="handleConfirm(order)">
                完成订单
              </button>
              <button class="view-delivery-btn" @click="handleViewDelivery(order)">
                查看物流
              </button>
            </template>

            <!-- 已完成状态 -->
            <template v-else-if="order.status === 4">
              <span class="status-badge completed">已完成</span>
              <button class="action-btn warning" @click="handleReturn(order)">
                申请退货
              </button>
              <button class="action-btn primary" @click="handleComment(order)">
                评论
              </button>
            </template>

            <!-- 已退货状态 -->
            <template v-else-if="order.status === 5">
              <span class="status-badge returned">已退货</span>
              <button class="action-btn primary" @click="handleComment(order)">
                评论
              </button>
            </template>

            <!-- 退货中状态 -->
            <template v-else-if="order.status === 6">
              <span class="status-badge returning">退货中</span>
            </template>

            <!-- 已评价状态 -->
            <template v-else-if="order.status === 7">
              <span class="status-badge commented">已评价</span>
              <button class="action-btn primary" @click="handleUpdateComment(order)">
                修改评论
              </button>
              <!-- <button class="action-btn danger" @click="handleDeleteComment(order)">
                删除评论
              </button> -->
            </template>
          </div>
        </div>

        <!-- 添加评论展示区域 -->
        <div v-if="order.status === 7" class="comment-section">
          <div class="comment-header">
            <span class="comment-title">我的评价</span>
            <div class="comment-rating">
              <el-rate :model-value="getCommentRating(order.id)" disabled show-score text-color="#ff9900" />
            </div>
          </div>
          <div class="comment-content">
            {{ getCommentContent(order.id) }}
          </div>
          <div v-if="getCommentImages(order.id)" class="comment-images">
            <el-image v-for="(image, index) in getCommentImages(order.id)" :key="index" :src="image"
              :preview-src-list="getCommentImages(order.id)" fit="cover" class="comment-image" />
          </div>
        </div>
      </div>
    </div>

    <!-- 分页组件 -->
    <div class="pagination" v-if="totalPages > 1">
      <button class="page-btn" :disabled="currentPage === 1" @click="changePage(currentPage - 1)">
        上一页
      </button>
      <div class="page-numbers">
        <button v-for="page in displayedPages" :key="page" :class="['page-number', { active: currentPage === page }]"
          @click="changePage(page)">
          {{ page }}
        </button>
      </div>
      <button class="page-btn" :disabled="currentPage === totalPages" @click="changePage(currentPage + 1)">
        下一页
      </button>
    </div>

    <CommentDialog v-model:visible="showCommentDialog" :order-id="currentOrderId" :is-update="isUpdateComment"
      :comment="orders.find(o => o.id === currentOrderId)?.comment" @submit="handleCommentSubmit" />

    <!-- 注释掉DeliveryMapDialog组件的使用 -->
    <!-- <DeliveryMapDialog
      v-model:visible="showDeliveryDialog"
      :shipping-address="currentDeliveryInfo.shippingAddress"
      :delivery-address="currentDeliveryInfo.deliveryAddress"
    /> -->

  </div>
</template>

<script setup>
import { ref, computed, onMounted, watch, nextTick, onUnmounted } from 'vue'
import { useRouter } from 'vue-router'
import { getOrderList, cancelOrder, confirmOrder, returnOrder, commentOrder } from '../../axios/order'
import { ElMessage, ElMessageBox } from 'element-plus'
import { addComment, updateComment, deleteComment, getMyCommentList, getCommentByOrderId } from '../../axios/comment'
import CommentDialog from '../../components/CommentDialog.vue'

const router = useRouter()

// 返回上一页
const goBack = () => {
  router.back()
}

// 订单状态标签
const tabs = [
  { label: '全部', value: 'all' },
  { label: '待付款', value: 0 },
  { label: '已支付', value: 1 },
  { label: '已取消', value: 2 },
  { label: '已发货', value: 3 },
  { label: '已完成', value: 4 },
  { label: '已退货', value: 5 },
  { label: '退货中', value: 6 },
  { label: '已评价', value: 7 }
]
const orders = ref([])
const currentTab = ref('all')
const loading = ref(false)
const error = ref(null)

// 添加配送时间映射
const deliveryDaysMap = ref(new Map())

// 分页相关
const itemsPerPage = 9
const currentPage = ref(1)
const totalPages = computed(() => {
  return Math.ceil(filteredOrders.value.length / itemsPerPage)
})

// 显示的页码（最多显示5个页码）
const displayedPages = computed(() => {
  if (totalPages.value <= 5) {
    return Array.from({ length: totalPages.value }, (_, i) => i + 1)
  }

  const start = Math.max(1, currentPage.value - 2)
  const end = Math.min(totalPages.value, start + 4)

  return Array.from({ length: end - start + 1 }, (_, i) => start + i)
})

// 根据标签筛选订单
const filteredOrders = computed(() => {
  if (currentTab.value === 'all') {
    return orders.value
  }
  return orders.value.filter(order => order.status === currentTab.value)
})

// 当前页的订单
const paginatedOrders = computed(() => {
  const start = (currentPage.value - 1) * itemsPerPage
  const end = start + itemsPerPage
  return filteredOrders.value.slice(start, end)
})

// 设置标签并重置分页
const setTab = (tab) => {
  currentTab.value = tab
  currentPage.value = 1
}

// 更改页码
const changePage = (page) => {
  currentPage.value = page
}

// 获取订单列表
const fetchOrders = async () => {
  loading.value = true
  error.value = null

  try {
    const response = await getOrderList()
    console.log('订单列表响应:', response)

    if (Array.isArray(response)) {
      orders.value = response
      // 将评论信息存储到commentMap中
      orders.value.forEach(order => {
        if (order.comment) {
          commentMap.value.set(order.id, order.comment)
        }
      })
      console.log('获取到订单:', orders.value)
    } else {
      error.value = '获取订单列表失败'
    }

  } catch (err) {
    console.error('获取订单列表失败:', err)
    error.value = '获取订单列表失败，请稍后重试'
  } finally {
    loading.value = false
  }
}

// 获取订单状态文本
const getStatusText = (status) => {
  const statusMap = {
    0: '未支付',
    1: '已支付',
    2: '已取消',
    3: '已发货',
    4: '已完成',
    5: '已退货',
    6: '退货中',
    7: '已评价'
  }
  return statusMap[status] || '未知状态'
}

// 计算订单总数量
const getTotalQuantity = (items) => {
  if (!items || !Array.isArray(items)) return 0
  return items.reduce((total, item) => total + (item.quantity || 0), 0)
}

// 处理支付
const handlePay = (order) => {
  router.push({
    name: 'payment-confirm',
    query: {
      orderId: order.id
    }
  })
}

// 取消订单
const handleCancel = async (order) => {
  try {
    await ElMessageBox.confirm('确定要取消此订单吗？', '取消订单', {
      confirmButtonText: '确定',
      cancelButtonText: '取消',
      type: 'warning'
    })

    const response = await cancelOrder(order.id)
    if (response?.code === 1) {
      ElMessage.success('订单已取消')
      // 更新订单状态
      order.status = 2
    } else {
      ElMessage.error(response?.msg || '取消订单失败')
    }
  } catch (err) {
    if (err !== 'cancel') {
      console.error('取消订单失败:', err)
      ElMessage.error('取消订单失败，请稍后重试')
    }
  }
}

// 确认收货
const handleConfirm = async (order) => {
  // 检查订单状态是否为已发货
  if (order.status !== 3) {
    ElMessage.warning('只有已发货的订单才能完成')
    return
  }

  try {
    await ElMessageBox.confirm('确定要完成此订单吗？', '完成订单', {
      confirmButtonText: '确定',
      cancelButtonText: '取消',
      type: 'info'
    })

    const response = await confirmOrder(order.id)
    if (response?.code === 1) {
      ElMessage.success('订单已完成')
      // 更新订单状态
      order.status = 4
    } else {
      ElMessage.error(response?.msg || '完成订单失败')
    }
  } catch (err) {
    if (err !== 'cancel') {
      console.error('完成订单失败:', err)
      ElMessage.error('完成订单失败，请稍后重试')
    }
  }
}

// 申请退货
const handleReturn = async (order) => {
  try {
    await ElMessageBox.confirm('确定要申请退货吗？', '申请退货', {
      confirmButtonText: '确定',
      cancelButtonText: '取消',
      type: 'warning'
    })

    const response = await returnOrder(order.id)
    if (response?.code === 1) {
      ElMessage.success('退货申请已提交')
      // 更新订单状态
      order.status = 5
    } else {
      ElMessage.error(response?.msg || '申请退货失败')
    }
  } catch (err) {
    if (err !== 'cancel') {
      console.error('申请退货失败:', err)
      ElMessage.error('申请退货失败，请稍后重试')
    }
  }
}

// 格式化价格
const formatPrice = (price) => {
  if (!price) return '0.00'
  return Number(price).toFixed(2)
}

// 监听标签变化，重置分页
watch(currentTab, () => {
  currentPage.value = 1
})

// 在 setup 中添加
const showCommentDialog = ref(false)
const currentOrderId = ref(0)  // 修改初始值为0
const isUpdateComment = ref(false)

// 存储评论信息的Map
const commentMap = ref(new Map())

// 获取我的评论列表
const fetchMyComments = async () => {
  try {
    const response = await getMyCommentList()

    if (response?.code === 1 && Array.isArray(response.data)) {
      // 将评论信息存储到Map中，以订单ID为key
      response.data.forEach(comment => {
        commentMap.value.set(comment.orderId, comment)
      })
    }
  } catch (error) {
    console.error('获取评论列表失败:', error)
  }
}

// 删除评论
const handleDeleteComment = async (order) => {
  try {
    await ElMessageBox.confirm('确定要删除此评论吗？', '删除评论', {
      confirmButtonText: '确定',
      cancelButtonText: '取消',
      type: 'warning'
    })

    const comment = commentMap.value.get(order.id)
    if (!comment) {
      ElMessage.error('未找到评论信息')
      return
    }

    const response = await deleteComment(comment.id)
    if (response?.code === 1) {
      ElMessage.success('评论删除成功')
      // 从Map中移除评论
      commentMap.value.delete(order.id)
      // 从订单中移除评论
      if (order.comment) {
        order.comment = null
      }
      // 恢复订单状态
      // 如果订单之前是已退货状态，则恢复为已退货
      if (order.status === 7 && order.returnStatus === 1) {
        order.status = 5 // 已退货
      } else {
        order.status = 4 // 已完成
      }
      await fetchOrders() // 刷新订单列表
    } else {
      ElMessage.error(response?.msg || '删除评论失败')
    }
  } catch (err) {
    if (err !== 'cancel') {
      console.error('删除评论失败:', err)
      ElMessage.error('删除评论失败，请稍后重试')
    }
  }
}

// 打开评论对话框
const handleComment = (order) => {
  if (!order || !order.id) {
    ElMessage.error('订单信息不完整')
    return
  }
  currentOrderId.value = order.id
  isUpdateComment.value = false
  showCommentDialog.value = true
}

// 打开修改评论对话框
const handleUpdateComment = async (order) => {
  if (!order || !order.id) {
    ElMessage.error('订单信息不完整')
    return
  }

  // 直接使用订单中的评论数据
  if (order.comment) {
    currentOrderId.value = order.id
    isUpdateComment.value = true
    showCommentDialog.value = true
  } else {
    ElMessage.error('未找到评论信息')
  }
}

// 处理评论提交
const handleCommentSubmit = async (commentData) => {
  if (!commentData.orderId) {
    ElMessage.error('订单信息不完整')
    return
  }

  try {
    console.log('提交的评论数据:', commentData)
    let response

    if (isUpdateComment.value) {
      // 修改评论时，构建CommentDTO格式的数据
      const updateData = {
        orderId: commentData.orderId,
        content: commentData.content,
        rating: commentData.rating,
        images: commentData.images,
        isAnonymous: commentData.isAnonymous ? 1 : 0
      }

      response = await updateComment(updateData)
      if (response?.code === 1) {
        // 更新Map中的评论信息
        const comment = commentMap.value.get(commentData.orderId)
        if (comment) {
          commentMap.value.set(commentData.orderId, {
            ...comment,
            ...updateData
          })
        }
        // 更新订单中的评论信息
        const order = orders.value.find(o => o.id === commentData.orderId)
        if (order) {
          order.comment = {
            ...comment,
            ...updateData
          }
        }
        ElMessage.success('评论修改成功')
      }
    } else {
      response = await addComment(commentData)
      // 评论成功后调用修改订单状态的接口
      if (response?.code === 1) {
        await commentOrder(commentData.orderId)
        // 更新订单状态为已评价
        const order = orders.value.find(o => o.id === commentData.orderId)
        if (order) {
          order.status = 7
          // 添加新评论到订单中
          order.comment = {
            id: response.data,
            ...commentData
          }
        }
        // 将新评论添加到Map中
        commentMap.value.set(commentData.orderId, {
          id: response.data,
          ...commentData
        })
        ElMessage.success('评论提交成功')
      }
    }

    if (response?.code === 1) {
      await fetchOrders() // 刷新订单列表
    } else {
      ElMessage.error(response?.msg || '评论提交失败')
    }
  } catch (error) {
    console.error('提交评论失败:', error)
    ElMessage.error('提交评论失败，请重试')
  }
}

// 获取评论评分
const getCommentRating = (orderId) => {
  const comment = commentMap.value.get(orderId)
  return comment?.rating || 0
}

// 获取评论内容
const getCommentContent = (orderId) => {
  const comment = commentMap.value.get(orderId)
  return comment?.content || ''
}

// 获取评论图片
const getCommentImages = (orderId) => {
  const comment = commentMap.value.get(orderId)
  return comment?.images ? comment.images.split(',') : []
}

// 处理查看物流
const handleViewDelivery = (order) => {
  router.push({
    name: 'logistics-tracking',
    params: {
      orderNo: order.orderNo
    },
    query: {
      address: order.fullAddress || '暂无收货地址'
    }
  })
}

onMounted(async () => {
  await Promise.all([
    fetchOrders(),
    fetchMyComments()
  ])
})

</script>

<style scoped>
.order-list-container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 30px;
  background-color: #f8f9fa;
  min-height: calc(100vh - 60px);
  position: relative;
  z-index: 1;
}

.back-button {
  position: absolute;
  top: 10px;
  left: 30px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 20px;
  background: white;
  border: none;
  border-radius: 30px;
  font-size: 16px;
  color: #2c3e50;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
  transition: all 0.3s ease;
  z-index: 10;
}

.back-button:hover {
  transform: translateX(-4px);
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.12);
  background: #f8f9fa;
}

.back-icon {
  font-size: 20px;
  font-weight: 500;
}

.back-text {
  font-weight: 500;
}

.page-header {
  display: flex;
  flex-direction: column;
  align-items: center;
  margin-bottom: 30px;
  margin-top: 40px;
}

.page-title {
  font-size: 28px;
  color: #2c3e50;
  margin-bottom: 20px;
  font-weight: 600;
}

.order-tabs {
  display: flex;
  gap: 10px;
  overflow-x: auto;
  padding-bottom: 10px;
  max-width: 100%;
}

.tab-btn {
  padding: 8px 16px;
  border: 1px solid #ddd;
  border-radius: 20px;
  background: white;
  color: #666;
  cursor: pointer;
  transition: all 0.3s;
  white-space: nowrap;
}

.tab-btn:hover {
  background: #f5f5f5;
}

.tab-btn.active {
  background: #4CAF50;
  color: white;
  border-color: #4CAF50;
}

.order-list {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.order-card {
  background: white;
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.05);
  display: flex;
  flex-direction: column;
}

.order-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 15px 20px;
  border-bottom: 1px solid #eee;
  background: #f8f9fa;
}

.order-info {
  display: flex;
  gap: 20px;
  color: #666;
  font-size: 14px;
}

.order-id {
  font-weight: 500;
}

.order-status {
  font-weight: 600;
}

.status-0 {
  color: #ff9800;
  /* 未支付 - 橙色 */
}

.status-1 {
  color: #2196F3;
  /* 已支付 - 蓝色 */
}

.status-2 {
  color: #9e9e9e;
  /* 已取消 - 灰色 */
}

.status-3 {
  color: #4CAF50;
  /* 已发货 - 绿色 */
}

.status-4 {
  color: #4CAF50;
  /* 已完成 - 绿色 */
}

.status-5 {
  color: #F44336;
  /* 已退货 - 红色 */
}

.status-6 {
  color: #ff9800;
  /* 退货中 - 橙色 */
}

.status-7 {
  color: #4CAF50;
  /* 已评价 - 绿色 */
}

.order-items {
  flex: 1;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 15px;
}

.order-item {
  display: flex;
  gap: 15px;
  padding-bottom: 15px;
  border-bottom: 1px solid #eee;
}

.order-item:last-child {
  border-bottom: none;
  padding-bottom: 0;
}

.item-image {
  width: 80px;
  height: 80px;
  border-radius: 8px;
  overflow: hidden;
}

.item-image img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.item-info {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.item-name {
  font-size: 16px;
  margin: 0;
  color: #2c3e50;
  font-weight: 500;
}

.item-price-qty {
  display: flex;
  justify-content: space-between;
  color: #666;
}

.price {
  font-weight: 500;
}

.order-footer {
  padding: 15px 20px;
  border-top: 1px solid #eee;
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: #f8f9fa;
}

.order-total {
  color: #666;
}

.total-price {
  margin-left: 15px;
  color: #e74c3c;
  font-weight: 600;
}

.order-actions {
  display: flex;
  gap: 10px;
}

.action-btn {
  padding: 8px 15px;
  border-radius: 6px;
  border: 1px solid #ddd;
  background: white;
  color: #666;
  cursor: pointer;
  transition: all 0.3s;
}

.action-btn:hover {
  background: #f5f5f5;
}

.action-btn.primary {
  background: #4CAF50;
  color: white;
  border-color: #4CAF50;
}

.action-btn.primary:hover {
  background: #45a049;
}

.action-btn.warning {
  background: #ff9800;
  color: white;
  border-color: #ff9800;
}

.action-btn.warning:hover {
  background: #f57c00;
}

.action-btn.danger {
  background: #f44336;
  color: white;
  border-color: #f44336;
}

.action-btn.danger:hover {
  background: #e53935;
}

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 60px 0;
  background: white;
  border-radius: 12px;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.05);
}

.empty-state i {
  font-size: 60px;
  color: #ddd;
  margin-bottom: 20px;
}

.empty-state p {
  color: #666;
  font-size: 18px;
}

.status-badge {
  padding: 4px 8px;
  border-radius: 4px;
  font-size: 14px;
  font-weight: 500;
}

.status-badge.paid {
  background: #e3f2fd;
  color: #2196F3;
}

.status-badge.cancelled {
  background: #f5f5f5;
  color: #9e9e9e;
}

.status-badge.shipped {
  background: #e8f5e9;
  color: #4CAF50;
}

.status-badge.completed {
  background: #e8f5e9;
  color: #4CAF50;
}

.status-badge.returned {
  background: #ffebee;
  color: #F44336;
}

.status-badge.returning {
  background: #fff3e0;
  color: #ff9800;
}

.status-badge.commented {
  background: #e8f5e9;
  color: #4CAF50;
}

.loading-container,
.error-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 60px 0;
  background: white;
  border-radius: 12px;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.05);
}

.loading-spinner {
  width: 40px;
  height: 40px;
  border: 4px solid #f3f3f3;
  border-top: 4px solid #4CAF50;
  border-radius: 50%;
  margin-bottom: 20px;
  animation: spin 1s linear infinite;
}

@keyframes spin {
  0% {
    transform: rotate(0deg);
  }

  100% {
    transform: rotate(360deg);
  }
}

.error-container p {
  color: #f44336;
  margin-bottom: 20px;
}

.retry-btn {
  padding: 8px 15px;
  background: #4CAF50;
  color: white;
  border: none;
  border-radius: 6px;
  cursor: pointer;
}

.pagination {
  margin-top: 30px;
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 10px;
}

.page-btn {
  padding: 8px 15px;
  border: 1px solid #ddd;
  background: white;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.3s;
}

.page-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.page-numbers {
  display: flex;
  gap: 5px;
}

.page-number {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid #ddd;
  border-radius: 6px;
  background: white;
  cursor: pointer;
  transition: all 0.3s;
}

.page-number.active {
  background: #4CAF50;
  color: white;
  border-color: #4CAF50;
}

@media (max-width: 768px) {
  .order-tabs {
    width: 100%;
    justify-content: start;
  }

  .order-footer {
    flex-direction: column;
    align-items: flex-start;
    gap: 15px;
  }

  .order-actions {
    width: 100%;
    justify-content: flex-end;
  }
}

/* 添加评论相关样式 */
.comment-section {
  padding: 20px;
  border-top: 1px solid #eee;
  background: #fafafa;
}

.comment-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 15px;
}

.comment-title {
  font-size: 16px;
  font-weight: 500;
  color: #2c3e50;
}

.comment-rating {
  display: flex;
  align-items: center;
}

.comment-content {
  font-size: 14px;
  color: #666;
  line-height: 1.6;
  margin-bottom: 15px;
  white-space: pre-wrap;
}

.comment-images {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.comment-image {
  width: 100px;
  height: 100px;
  border-radius: 8px;
  object-fit: cover;
  cursor: pointer;
  transition: transform 0.3s;
}

.comment-image:hover {
  transform: scale(1.05);
}

/* 调整订单卡片样式以适应评论区域 */
.order-card {
  display: flex;
  flex-direction: column;
}

.order-items {
  flex: 1;
}

/* 响应式调整 */
@media (max-width: 768px) {
  .comment-images {
    gap: 8px;
  }

  .comment-image {
    width: 80px;
    height: 80px;
  }
}

/* 添加样式 */
.view-delivery-btn {
  margin-left: 10px;
  padding: 4px 8px;
  background-color: #409EFF;
  color: white;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  font-size: 12px;
}

.view-delivery-btn:hover {
  background-color: #66b1ff;
}
</style>